import os
import random
import matplotlib.pyplot as plt


class ZodiacTraining:

    def __init__(self) -> None:
        self.myShuXiang = '蛇' # 自己的属相
        self.shuxiang = ['鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪']
        self.questionMap = {}
        self.randidx = 0
        self.max = len(self.shuxiang)
        for idx in range(self.max):
            value = self.shuxiang.index(self.myShuXiang) - idx
            self.questionMap[self.shuxiang[idx]] = value

        print(f"-------------------------{self.max} 生肖偏移量表格-----------------------")
        pass

    def start(self):
        n = ""
        result = True
        while(n != "q"):
            if result: # 重新出题
                self.randidx = self.generateRandomIdx()
            
            q = self.shuxiang[self.randidx]
            a = self.questionMap[q]
            n = input(f"我属{q}:")

            try:   
                if a == int(n):
                    result = True
                    print("正确")                    
                else:
                    result = False
                    print("错误")
                    self.showPhoto(f"photo/{q}.png")
            except:
                pass

    def generateRandomIdx(self)->int:
        myidx = self.shuxiang.index(self.myShuXiang)
        randidx_tmp = random.randint(0,len(self.shuxiang) - 1)
        
        while(myidx == randidx_tmp or randidx_tmp == self.randidx):            
            randidx_tmp = random.randint(0,len(self.shuxiang) - 1)
        return randidx_tmp
       
    def showPhoto(self,path):
        if os.path.exists(path):
            img = plt.imread(path)     # 读取图片文件
            plt.imshow(img)                   # 显示图片
            plt.show()




ZodiacTraining().start()